package per.qiao.simplerest.restargument;

import org.springframework.util.ObjectUtils;
import org.springframework.web.util.UrlPathHelper;
import per.qiao.simplerest.restenum.ParameterStyle;
import per.qiao.simplerest.restresolver.RestInvokerMethod;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Company: 上海数惠系统技术有限公司
 * Department: 数据中心
 * Date: 2020-06-01 9:45
 *
 * @Author: qyp
 * Email: qiaoyp@dist.com.cn
 * Desc:
 */
public class DefulatArgumentResolver implements RestArgumentResolver {


    @Override
    public RestArgumentValue resolver(RestInvokerMethod restInvokerMethod) {
        RestParameter[] restParameters = restInvokerMethod.getRestParameter();
        if (ObjectUtils.isEmpty(restParameters)) {
            return null;
        }

        // 1. resturi参数  2. formData参数(?a=2) 3.@RequestBody参数
        RestArgumentValue restArgumentValue = new RestArgumentValue();
        for (int i = 0; i < restParameters.length; i++) {
            RestParameter restParameter = restParameters[i];
            ParameterStyle parameterStyle = restParameter.getParameterStyle();
            Object value = restParameter.getValue();
            switch (parameterStyle) {
                case REQUESTPARAM:
                    restArgumentValue.addRequestParamValue(restParameter.getName(), value);
                case RESTFUL:
                    restArgumentValue.addRestfulValue(value);
                    break;
                case REQUESTBODY:
                    restArgumentValue.setBodyValue(value);
                    break;
                    default: break;
            }
        }
        return restArgumentValue;
    }

}
